#include "selectiontoolatd.h"

SelectionToolATD::SelectionToolATD()
{
    select = SelectionTool::getInstance();
}

Result SelectionToolATD::setCoords(vector3<int> start, vector3<int> end){
    return select->setEndCoords(end)&& select->setStartCoords(start);
}

void SelectionToolATD::testActiveSelection(){
    BrushUtilities* brush = BrushUtilities::getInstance();
    brush->setShape(BrushUtilities::CUBE);
    brush->setSize(19);
    brush->coords = vector3<int>(20,20,20);
    brush->execute(BrushUtilities::ADD);
    select->action = SelectionTool::ADD;
    setCoords(vector3<int>(12,12, 20), vector3<int>(15,15,21));
    select->execute();
    setCoords(vector3<int>(12,12,20), vector3<int>(25, 25, 25));
    select->execute();
    bool a = select->global->findInSelection(12, 12, 20);
    select->action= SelectionTool::EDIT_ADD;
    setCoords(vector3<int>(13, 13, 21), vector3<int>(23, 23,23));
    a &= select->global->findInSelection(12,12,20);
    a&= !select->global->findInSelection(25,25,25);
    TEST(1, a==true);
    select->global->clearSelection();
}

void SelectionToolATD::testValidCoords(){
    TestDriver::resTest(2, false, setCoords(vector3<int>(-53,10,10), vector3<int>(2,2,2)));
    TestDriver::resTest(3, false, setCoords(vector3<int>(10,10,10), vector3<int>(600,2,2)));
    TestDriver::resTest(4, false, setCoords(vector3<int>(5,5,5), vector3<int>(2,2,2)));
    TestDriver::resTest(5, true, setCoords(vector3<int>(0,0,0), vector3<int>(20,20,2)));
}

void SelectionToolATD::testMode(){
    QMouseEvent * a = new QMouseEvent(QEvent::MouseButtonPress,
                                      QPoint(30, 30), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier);
    QMouseEvent * b = new QMouseEvent(QEvent::MouseButtonPress,
                                      QPoint(30, 30), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
    select->mousePressEvent(a);
    TEST(6, select->mode==SelectionTool::TRANSLATE);
    select->mousePressEvent(b);
    TEST(7, select->mode==SelectionTool::SCALE);
    select->global->clearSelection();
}


void SelectionToolATD::testAction(){
    QMouseEvent * a = new QMouseEvent(QEvent::MouseButtonPress,
                                      QPoint(30, 30), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
    select->action= SelectionTool::ADD;
    select->mousePressEvent(a);
    TEST(8, select->action==SelectionTool::EDIT_ADD);
    select->global->clearSelection();
}
